<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <style> 

    .box {
      width: 100px;
      height: 100px;
      background-color: blue;
    }
  </style>
</head>
<body>

  <div class="box"></div>

  <script>

    function debounce(fn, delay, options) {
      let timer = null;

      const {
        leading = false,
        trailing = true
      } = options;
      return function (...args) {
        
        if (leading) {
          if (!timer) {
            fn.apply(this, args)
          }
        }

        if (timer) {
          clearTimeout(timer);
        }
        timer = setTimeout(() => {
          if (trailing) {
            lastExecTime = Date.now()
            fn.apply(this, args);
          }
          timer = null
        }, delay);
      };

    }

    const debounceClick = debounce(() => {
      console.log('333')
    }, 1000, {
      leading: false,
      trailing: true,
      // maxWait: 3000
    })

    document.querySelector('.box').onclick = () => {
      debounceClick()
    }

    
  </script>
</body>
</html>